<?php
require_once ("db_manage.php");
require_once 'comment_class.php';

function getCommentArray($sql) {
	$comment_array = array ();
	$result = mysql_query ( $sql );
	$i = 0;
	while ( ($rs = mysql_fetch_object ( $result )) != false ) {
		$comment = new Comment ();
		$comment->setId ( $rs->id );
		$comment->setFid ( $rs->fid );
		$comment->setComment ( $rs->comment );
		$comment->setPostuser ( $rs->postuser );
		$comment->setUsername ( $rs->username );
		$comment->setState ( $rs->state );
		$comment->setModule ( $rs->module );
		$comment->setPostdate ( $rs->postdate );
		$comment->setTimestamp ( $rs->timestamp );
		$comment_array [$i] = $comment;
		$i ++;
	}
	return $comment_array;
}

function getCommentsByModuleAndId($module, $id) {
	$sql = "select * from pcd_comment,cdb_members where module = '" . $module . "' and  postuser = uid and fid = '" . $id . "'";
	return getCommentArray ( $sql );
}

function getNumberOfEachModule($module) {
	$sql = " select fid,count(*) as number from pcd_comment where module = '" . $module . "' group by fid ";
	$result = mysql_query ( $sql );
	$array = array ();
	while ( ($rs = mysql_fetch_object ( $result )) != false ) {
		$array [$rs->fid] = $rs->number;
	}
	return $array;
}
?>